package com.yelobblog.yelobblog.controller;

import com.yelobblog.yelobblog.common.untils.Response;
import com.yelobblog.yelobblog.domain.Dto.commentsDto;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.yelobblog.yelobblog.service.commentService;
@RestController
@RequestMapping("/comment")
public class commentController {
    @Resource
    private commentService commentService;
    @PostMapping("/add")
    public Response<?> addComment(@RequestBody commentsDto commentsDto) {
        commentService.addComment(commentsDto);
        return Response.success();
    }
    @DeleteMapping("/delete")
    public Response<?> deleteComment(Integer id) {
        commentService.deleteComment(id);
        return Response.success();
    }
    @GetMapping("/list/{articleId}")
    public Response<?> list(@PathVariable Integer articleId,
                            @RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Response.success(commentService.getCommentsByArticleId( pageNum, pageSize,articleId));
    }
    @GetMapping("/listRoot/{rootCommentsId}")
    public Response<?> listRoot(@PathVariable Integer rootCommentsId,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        return Response.success(commentService.getCommentsByrootCommentsId( pageNum, pageSize,rootCommentsId));
    }
    @PostMapping("/like")
    public Response<?> likeComment(Integer id) {
        commentService.likeComment(id);
        return Response.success();
    }
    @PostMapping("/dislike")
    public Response<?> dislikeComment(Integer id) {
        commentService.dislikeComment(id);
        return Response.success();
    }
    @GetMapping("/count/{commentId}")
    public Response<?> count(@PathVariable Integer commentId) {
        return Response.success(commentService.getCommentLike(commentId));
    }
}
